/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SComplaintConverter.java
 * Created：		2016年8月21日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.repair.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.SAttachmentConverter;
import com.thor.palmmall.rest.common.SOpeateInfoConverter_v2;
import com.thor.palmmall.rest.common.SSourceBillConverter;
import com.thor.palmmall.rest.repair.ARepairBill;
import com.thor.palmmall.spi.maintain.SMaintainBill;
import com.thor.palmmall.spi.maintain.SMaintainEvaluation;

/**
 * @author wolv
 *
 */
public class SMaintainBillConverter implements Converter<ARepairBill, SMaintainBill> {

  public static SMaintainBillConverter getInstance() {
    if (instance == null)
      instance = new SMaintainBillConverter();
    return instance;
  }

  private static SMaintainBillConverter instance;

  private SMaintainBillConverter() {
  }

  @Override
  public SMaintainBill convert(ARepairBill source) {
    if (source == null)
      return null;

    SMaintainBill target = new SMaintainBill();
    target.setAfterPictures(
        ConverterUtil.convert(source.getAfterPictures(), SAttachmentConverter.getInstance()));
    target.setAppointmentTime(source.getAppointmentTime());
    target.setBeforePictures(
        ConverterUtil.convert(source.getBeforePictures(), SAttachmentConverter.getInstance()));
    target.setBillNumber(source.getBillNumber());
    target.setBizState(source.getBizState());
    target.setContactInfo(source.getContactInfo());
    target.setContract(UCN.newInstance(source.getContract()));
    if (source.getEvaluation() != null) {
      target.setEvaluation(SMaintainEvaluation.valueOf(source.getEvaluation().name()));
    }
    target.setMaintainBeginTime(source.getMaintainBeginTime());
    target.setMaintainEndTime(source.getMaintainEndTime());
    target.setMaintainContent(source.getMaintainContent());
    target.setMaintainType(source.getMaintainType());
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setRepairRecord(SRepairRecordConverter.getInstance().convert(source.getRepairRecord()));
    target.setStore(UCN.newInstance(source.getStore()));
    target.setTenant(UCN.newInstance(source.getTenant()));
    target.setTenantEvaluation(source.getTenantEvaluation());
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());
    target.setMaintainAddress(source.getMaintainAddress());
    target.setSolve(source.getSolve());
    target.setSourceBill(SSourceBillConverter.getInstance().convert(source.getSourceBill()));
    target.setWorkOrder(SWorkOrderConverter.getInstance().convert(source.getWorkOrder()));
    target.setType(source.getType());
    target.setHandler(source.getHandler());
    target.setReportDate(source.getReportDate());
    target.setMaintainObject(source.getMaintainObject());
    target.setApplicant(source.getApplicant());
    target.setEvaluateUser(source.getEvaluateUser());
    target.setEvaluateTime(source.getEvaluateTime());
    target.setTransferOther(source.getTransferOther());
    target.setAttachments(
        ConverterUtil.convert(source.getAttachments(), SAttachmentConverter.getInstance()));
    target.setTransferInfos(
        ConverterUtil.convert(source.getTransferInfos(), STransferInfoConverter.getInstance()));
    target.setAbortMsg(source.getAbortMsg());
    target.setBpmInstance(source.getBpmInstance());
    target.setBpmMessage(source.getBpmMessage());
    target.setBpmState(source.getBpmState());
    target.setBpmOutgoingState(source.getBpmOutgoingState());
    target.setRemark(source.getRemark());
    target.setCompletionInfo(source.getCompletionInfo());
    target.setLastModifyInfo(
        SOpeateInfoConverter_v2.getInstance().convert(source.getLastModifyInfo()));
    target.setCreateInfo(SOpeateInfoConverter_v2.getInstance().convert(source.getCreateInfo()));
    target.setSubmitTime(source.getSubmitTime());
    target.setDealTime(source.getDealTime());
    target.setDealUser(source.getDealUser());
    target.setFinishTime(source.getFinishTime());
    return target;
  }
}
